package com.caird.pmp.iot.message.impl;

import com.caird.pmp.iot.message.MessageBase;
import io.netty.buffer.ByteBuf;
import lombok.Data;

@Data
public class ServerMessage8100 extends MessageBase {


    public ServerMessage8100() {
        id = (short)0x8100;
    }

    @Override
    public int getMaxBodyLength() {
        return 35;
    }

    @Override
    public boolean encodeBody(ByteBuf raw) {
        if (null == auth || auth.length() > 32)
            return false;

        if (3 + auth.length() > raw.writableBytes())
            return false;

        //应答流水号
        raw.writeShort(resFlowNo);

        //结果码
        raw.writeByte(result);

        //鉴权码
        raw.writeBytes(auth.getBytes());

        return true;
    }

    //应答流水号
    private short resFlowNo;

    //结果：0-成功  1-车辆已被注册  2-数据库无该车辆  3-终端已被注册  4-数据库中无该终端
    private byte result;

    //鉴权码
    private String auth;

}
